import java.util.SortedMap;
import java.util.TreeMap;

/**
 * @author zhangdi
 * @version 1.0
 * @date 2022.6.29 15:49
 */
public class HashInfo {
    String[] servers = {"192.168.0.1", "192.168.0.21"};
    String[] ids = {"1", "2", "3", "4"};
    SortedMap<Long, String> serverMap = new TreeMap<>();

    //每个服务器虚拟n个节点
    int virtualCount = 10;

    public static void main(String[] args) {
        int p = 16777619;
        int hash = (int)2166136261L;
        String[] key = {"192.168.10.18","192.168.10.19","192.168.10.20"};

        for (String s : key) {
            HashInfo.hash0(s);
        }
    }

    public static void hash0(String key){
        int p = 16777619;
        int hash = (int)2166136261L;
        for (int i = 0; i < key.length(); i++) {
            hash = (hash ^ key.charAt(i))*p;
        }
        hash += hash << 13;
        hash ^= hash << 7;
        hash += hash << 3;
        hash ^= hash << 17;
        hash += hash << 5;
        if(hash < 0) {
            hash = Math.abs(hash);
        }
        System.out.println(hash);
    }

    public static void hash1(String key){
        int hash = 0;
        for (int i = 0; i < key.length(); i++) {
            hash = (hash<<4>>28)^key.charAt(i);
        }
        if(hash < 0) {
            hash = Math.abs(hash);
        }
        System.out.println(hash);
    }
}
